package com.briup.cms.web.controller;


import com.briup.cms.bean.Category;
import com.briup.cms.service.CategoryService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-08-31
 */
@Api(tags = "栏目模块")
@RestController
@RequestMapping("/auth/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @ApiOperation(value = "新增栏目")
    @PostMapping("/save")
    public Result save(@RequestBody Category category){
        categoryService.save(category);
        return Result.success("新增栏目成功");
    }
    @ApiOperation("根据id查询栏目信息")
    @GetMapping("/getCategoryById/{id}")
    public Result getById(@PathVariable("id") Long id){
        return Result.success(categoryService.getById(id));
    }
    @ApiOperation("更新栏目")
    @PutMapping("/update")
    public Result update(@RequestBody Category category){
        categoryService.update(category);
        return Result.success("更新栏目成功");
    }
    @ApiOperation("分页查询所有栏目")
    @GetMapping("/query")
    public Result query(@RequestParam("pageNum") Integer pageNum,
                        @RequestParam("pageSize") Integer pageSize,
                        Integer parentId){
        return Result.success(categoryService.query(pageNum,pageSize,parentId));
    }
    @ApiOperation("查询所有栏目")
    @GetMapping("/queryAllParent")
    public Result queryAllParent(){
        return Result.success(categoryService.selectAllParent());
    }
}

